package com.suxin.data.filter;

import lombok.Getter;

import java.util.Arrays;
import java.util.List;

/**
 * @author Tang
 * @classname DefaultDataFilterChain
 * @description [  ]
 * @date 2021/12/2 16:37
 */
public class DefaultDataFilterChain implements DataFilterChain {

    @Getter
    private List<? extends DataFilter> dataFilters;

    public DefaultDataFilterChain(List<? extends DataFilter> dataFilters) {
        this.dataFilters = dataFilters;
    }

    public DefaultDataFilterChain(DataFilter... dataFilters) {
        this.dataFilters = Arrays.asList(dataFilters);
    }

    @Override
    public Object doFilterChain(Object data) {
        for (DataFilter dataFilter : dataFilters) {
            data = dataFilter.doFilter(data);
        }
        return data;
    }

    @Override
    public List<? extends DataFilter> getDataFilters() {
        return dataFilters;
    }
}